<template>
  <div>
    <!-- 搜索 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="2" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :dataSource="dataList"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      height="auto"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()" :disabled="disableds">保 存</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
import { getPartList } from '@/api/claim/factory/PartsTypeMaintain';
export default {
  data() {
    return {
      disableds: true,
      dataList: [],
      visible: false,
      collapse: false,
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchapi: getPartList,
      fetchParams: {}, //参数
      selectedRows: [], //选中经销商
    };
  },
  created() {
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = this.selectedRows.length <= 0;
      console.log(this.selectedRows);
    },
    saveDialog() {
      // this.$refs.formPanel1.SUBMIT_FORM();
      if (this.selectedRows.length) {
        this.$emit('save', this.selectedRows);
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '配件代码', fieldName: 'partCode', placeholder: '请输入配件代码...', initialValue: '' },
        { type: 'INPUT', label: '配件名称', fieldName: 'partName', placeholder: '请输入配件名称...', initialValue: '' }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '配件代码', dataIndex: 'partCode', sorter: true},
        {title: '配件名称', dataIndex: 'partName', sorter: true},
        {title: '单位', dataIndex: 'partUnit', sorter: true, width: 80},
        {title: '数量', dataIndex: 'partCount', sorter: true, width: 80},
        {title: '索赔单价', dataIndex: 'claimPrice', sorter: true, width: 90},
        {title: '索赔总价', dataIndex: 'claimAmount', sorter: true},
        // {title: '是否电池', dataIndex: 'ifEv', sorter: true, width: 80}
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
